# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations
#########################################################################
## Customize your APP title, subtitle and menus here
#########################################################################

response.title = request.application
response.subtitle = T('Software Development')

#http://dev.w3.org/html5/markup/meta.name.html
response.meta.author = 'Rene Dohmen'
response.meta.description = 'Formatics implements and supports custom applications. Research, new development, prototyping, modification, reuse, re-engineering, maintenance are our key services.'
response.meta.keywords = 'webapplications, software, development'
response.meta.generator = 'Formatics'
response.meta.copyright = 'Copyright Formatics 2011-2015'

##########################################
## this is the main application menu
## add/remove items as required
##########################################
error=URL(r=request,f='error')

#MAIN MENU
if db((db.page.short_title == 'Home')).isempty():
    response.menu = [(T('Home'), False, URL('default','index'), [])]
pages=db((db.page.parent==0) & (db.page.language==T.accepted_language)).select(orderby=db.page.order_nr)
for page in pages:
    sub_pages=db(db.page.parent==page.id).select(orderby=db.page.order_nr)
    if len(sub_pages)<11:
        submenu=[]
        for sub_page in sub_pages:
            submenu.append([sub_page.short_title, False, URL('page','show/%s' % (sub_page.url))])
        response.menu.append((page.short_title, False, URL('page','show/%s' % (page.url)), submenu))
    else:
        response.menu.append((page.short_title, False, URL('page','show/%s' % (page.url))))

response.menu.append((T('Dashboard'), True, URL('dashboard','index')))
#response.menu.append((T('Sessions'), False, URL('dashboard','sessions')))
#response.menu.append((T('RPC Calls'), False, URL('dashboard','rpc_calls')))

#Context menu
response.right_menu=[]
response.navigation_helper=[]
if request.controller=="page" and (request.function=="show" or request.function=="showEditable"):
    try:
        page_id=int(request.args(0))
        page=db.page[page_id] or redirect(error)
    except:
        page=db(db.page.url==request.args(0)).select().first() or redirect(error)
        page_id=page.id
    
    if page.childrenTitle: response.right_menu_title=page.childrenTitle
    else: response.right_menu_title=page.short_title
    sub_pages=db(db.page.parent==page_id).select(orderby=db.page.order_nr)
    for sub_page in sub_pages:
        response.right_menu.append((sub_page.short_title, False, URL('page','show/%s' % (sub_page.url),[])))
    # deal with navigation helper
    parent=page.parent
    done=False
    while not done:
        try:
            temp_page=db.page[parent] or redirect(error)
            response.navigation_helper.insert(0,(temp_page.short_title, False, URL('page','show/%s' % (temp_page.url),[])))
            parent=temp_page.parent
        except:
            done=True
            
#response.menu.append([(T('Manage nodes'), False, URL('provision','manageNodes'), [])])
#response.menu.append([(T('Manage packages'), False, URL('provision','managePackages'), [])])


#Static items in context menu
response.right_menu_static = []
response.right_menu_form = []


